<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Rols extends CI_Controller {
	
	public function index(){
		
		$this->load->model('Rols_model');
		$rols = $this->Rols_model->getAll();
		
		$vars['rols'] = $rols;
		$vars['content_view'] = 'rols_list';
	    $vars['menu'] = 'users';
	    $this->load->view('template', $vars);
		
	}
	
	public function add($success_message = null)
	{
		         
		if (isset($success_message)){
			$vars['success_message'] = true;
		}
         
        $vars['content_view'] = 'rols_form';
	    $vars['menu'] = 'users';
	    $this->load->view('template', $vars);
	}
	
	public function edit($id_rol)
	{
	    $this->load->model('Rols_model');
	    $vars['rol'] = $this->Rols_model->find($id_rol);
	    $vars['content_view'] = 'rols_form';
	    $vars['menu'] = 'users';
	    $this->load->view('template', $vars);
	}
	
	
	public function delete($id_rol)
	{
	    $this->load->model('Rols_model');
        $this->Rols_model->delete($id_rol);
        $this->index();
	}
	
       


	
	public function submit()
	{
	   if($this->input->post('id_rol') != ''){
		   
		    if($this->input->post('description') != ''){
			
				$this->load->model('Rols_model');
				
				$id = $this->input->post('id_rol');
				
				$vars['description'] = $this->input->post('description');
				$vars['edit'] = $this->Rols_model->update($id, $vars);
				$vars['rol'] = $this->Rols_model->find($id);
				$vars['content_view'] = 'rols_form'; // varibale cque contiene el nombre del formulario  llamar
				$vars['menu'] = 'users'; //
				$this->load->view('template', $vars);	
				
			}else{
				
				$vars['success_message'] = 0;
				$vars['content_view'] = 'rols_form'; // varibale cque contiene el nombre del formulario  llamar
				$vars['menu'] = 'users'; //
				$this->load->view('template', $vars);		
				
			}
							
		}else{
			
			if($this->input->post('description') != ''){ 
			
				$this->load->model('Rols_model');
				
				$id = $this->input->post('id_rol');
                                $data['description'] = $this->input->post('description');
				
				
				$vars['success_message'] = $this->Rols_model->add($data);
				$vars['content_view'] = 'rols_form'; // varibale cque contiene el nombre del formulario  llamar
				$vars['menu'] = 'users'; //
				$this->load->view('template', $vars);
			
			}else{
				
				$vars['success_message'] = 0;
				$vars['content_view'] = 'rols_form'; // varibale cque contiene el nombre del formulario  llamar
				$vars['menu'] = 'users'; //
				$this->load->view('template', $vars);
				
			
			}
			
			
			
			
		}	
		
	}
	
	
   /*     public function evalue()
			{
	    if ($this->input->post('id_rol')) {
	        $id_rol = $this->input->post('id_rol');
	        $this->load->model('Rols_model');
	        $dataRol = $this->Rols_model->find($id_rol);
	        if ($dataRol) {
	            echo "true";
	        } else {
	            echo "false";
	        }
	    }
	}*/
	
	
}

?>